package cl.webservice;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;

import android.content.Context;
import android.content.SharedPreferences;

import com.google.gson.Gson;


public class WebserviceSms{

	private static String METHOD_NAME ;
	private static String NAMESPACE ;
	private static String URL;



	public void servidorsistema(String rutaservidor){


	}

	//	public void coneccionwsPropio(){
	//
	//		METHOD_NAME = "smsandroid";
	//		NAMESPACE = "http://ws.cl/";
	//		URL = "http://186.10.141.140:8080/AndroidSmsws/services/MensajesWs";
	//	}
	//

	public void coneccionwsServidorLon(String url){

		METHOD_NAME = "smsandroid";
		NAMESPACE = "http://ws.cl/";

		if(!url.equals("")){
			URL = "http://"+url+":8080/AndroidSmsws1/services/MensajesWs?wsdl";
		}
		else{
			URL = "http://londres.ceisufro.cl:8080/AndroidSmsws1/services/MensajesWs?wsdl";
		}
		//		URL = "http://200.13.4.205:8080/AndroidSmsws1/services/MensajesWs?wsdl";
	}

	/**
	 * 
	 * @param methodName
	 */

	public String obtenerSms(String url_servidor){

		coneccionwsServidorLon(url_servidor);

		String SOAP_ACTION = NAMESPACE + METHOD_NAME;

		SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
		SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		soapEnvelope.dotNet = true;
		soapEnvelope.implicitTypes =true;
		soapEnvelope.setOutputSoapObject(request);




		AndroidHttpTransport aht = new AndroidHttpTransport(URL);
		String res = aht.requestDump;
		String datosJsonString;
		try
		{
			aht.call(SOAP_ACTION, soapEnvelope);
			SoapPrimitive resultString = (SoapPrimitive)soapEnvelope.getResponse();
			datosJsonString =resultString.toString();
			return datosJsonString;
		}
		catch (Exception e)
		{
			e.printStackTrace();
			// en caso de no tener acceso al web service
			/*	if(METHOD_NAME=="traePaciente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decrypt64(var,"wsxedcrfv");
				datosJsonString = datosJsonString.replaceAll("\":\"","\":\"-FALLO WS-"); 

			}else{*/datosJsonString = "Error Conexion";}
		return datosJsonString;


	}
}
